package MeteoCal.entity;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @authors Guttadoro, Iommazzo, Saullo
 */
@Entity
@Table(name = "commentwritten")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Commentwritten.findAll", query = "SELECT c FROM Commentwritten c"),
    @NamedQuery(name = "Commentwritten.findByIdComment", query = "SELECT c FROM Commentwritten c WHERE c.commentwrittenPK.idComment = :idComment"),
    @NamedQuery(name = "Commentwritten.findByIdUser", query = "SELECT c FROM Commentwritten c WHERE c.commentwrittenPK.idUser = :idUser"),
    @NamedQuery(name = "Commentwritten.findByIdEvent", query = "SELECT c FROM Commentwritten c WHERE c.commentwrittenPK.idEvent = :idEvent")})
public class Commentwritten implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected CommentwrittenPK commentwrittenPK;
    @JoinColumn(name = "idComment", referencedColumnName = "idComment", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Comment comment;
    @JoinColumn(name = "idEvent", referencedColumnName = "idEvent", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Event event;

    public Commentwritten() {
    }

    public Commentwritten(CommentwrittenPK commentwrittenPK) {
        this.commentwrittenPK = commentwrittenPK;
    }

    public Commentwritten(int idComment, int idUser, int idEvent) {
        this.commentwrittenPK = new CommentwrittenPK(idComment, idUser, idEvent);
    }

    public CommentwrittenPK getCommentwrittenPK() {
        return commentwrittenPK;
    }

    public void setCommentwrittenPK(CommentwrittenPK commentwrittenPK) {
        this.commentwrittenPK = commentwrittenPK;
    }

    public Comment getComment() {
        return comment;
    }

    public void setComment(Comment comment) {
        this.comment = comment;
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (commentwrittenPK != null ? commentwrittenPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Commentwritten)) {
            return false;
        }
        Commentwritten other = (Commentwritten) object;
        if ((this.commentwrittenPK == null && other.commentwrittenPK != null) || (this.commentwrittenPK != null && !this.commentwrittenPK.equals(other.commentwrittenPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "MeteoCal.entity.Commentwritten[ commentwrittenPK=" + commentwrittenPK + " ]";
    }
    
}
